# -*- coding: utf-8 -*-
"""
@Project: base_python
@File: scrapetest.py
@Author: PC
@Date: 2025/04/29
@Description: 
"""

from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup

def getTitle(url):
    try:
        html = urlopen(url)
    except HTTPError as e:
        return None
    try:
        bs = BeautifulSoup(html.read(), 'html.parser')
        title = bs.body.h1
    except AttributeError as e:
        return None
    return title

title = getTitle('http://pythonscraping.com/pages/page11.html')
if title == None:
    print('title could not be found')
else:
    print(title)
